Fractale Tree  0.5
Plot Tree Fractale
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Draw_Tree Class Reference

lib de l'affichage de l'arbre More...

#include <draw_tree.h>

Collaboration diagram for Draw_Tree:
Collaboration graph
[legend]

Public Member Functions

 Draw_Tree ()
 Constructeur de la classe. More...
 
void Init (QGraphicsScene *scene, QProgressBar *ProgressBar_Plot)
 Initialise la class. More...
 
void Clear ()
 Clear la class. More...
 
void Plot (QWidget_trees *Widget_trees, QWidget_Config *Widget_Config, QWidget_Ratio *Widget_Ratio, QWidget_Graphique *Widget_Graphique)
 Desiner l'arbre. More...
 
void Save_file_svg (QString namefile)
 Cree un fichier SVG. More...
 

Private Member Functions

void Draw_Graph ()
 Desiner l'abre. More...
 
void Draw_Line ()
 
void Sub_Draw ()
 

Private Attributes

Frame frame
 
int niveau
 
int niveau_max
 
double lenght
 
double sizePen
 
double prcent_lenght
 
bool etat_ratio
 
QColor color
 
bool color_auto
 
bool with_bout
 
bool IsSaveSVG
 
QGraphicsScene * scene
 
Stock_Prcent stock_prcent
 
QFile file
 
double X_max
 
double Y_max
 
double X_min
 
double Y_min
 
QProgressBar * ProgressBar
 

Detailed Description

lib de l'affichage de l'arbre

La classe gere les fonctions d'affichage et de sauvegarde en SVG des arbres

Definition at line 32 of file draw_tree.h.

Constructor & Destructor Documentation

◆ Draw_Tree()

Draw_Tree::Draw_Tree ( )

Constructeur de la classe.

Constructeur de la classe.

Definition at line 15 of file draw_tree.cpp.

References IsSaveSVG.

16 {
17  //Marquage a false le flag SVG --> Pas de creation de fichier svg
18  IsSaveSVG=false;
19 }
bool IsSaveSVG
Definition: draw_tree.h:81

Member Function Documentation

◆ Clear()

void Draw_Tree::Clear ( )

Clear la class.

Remet à 0 les parametres de la class

Parameters
*scene: Scene du QWidget_Graphique
*ProgressBar_Plot: Barre de progression des calculs

Definition at line 79 of file draw_tree.cpp.

References frame, Frame::Init(), IsSaveSVG, lenght, scene, X_max, X_min, Y_max, and Y_min.

Referenced by Draw_Graph().

80 {
81  // Si IsSaveSVG=false --> Init les liniltes de l'abre
82  if(!IsSaveSVG)
83  {
84  X_max=0;
85  X_min=0;
86  Y_max=0;
87  Y_min=0;
88  }
89  // Init frame --> X=0 Y=0 d=l alpha = -90°
90  frame.Init(0,0,lenght,-90);
91 
92  //Init scene
93  scene->clear();
94 }
double Y_min
Definition: draw_tree.h:93
double X_min
Definition: draw_tree.h:92
bool IsSaveSVG
Definition: draw_tree.h:81
Frame frame
Definition: draw_tree.h:69
double Y_max
Definition: draw_tree.h:91
QGraphicsScene * scene
Definition: draw_tree.h:83
double X_max
Definition: draw_tree.h:90
void Init(double x, double y, double d, double alpha)
Definition: frame.cpp:4
double lenght
Definition: draw_tree.h:73
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Draw_Graph()

void Draw_Tree::Draw_Graph ( )
private

Desiner l'abre.

Desine l'abre

Definition at line 151 of file draw_tree.cpp.

References Clear(), color_auto, Draw_Line(), frame, Stock_Prcent::Get_Prcent_By_Index(), Stock_Prcent::Get_size(), lenght, Frame::Move(), niveau, niveau_max, ProgressBar, sizePen, stock_prcent, and Sub_Draw().

Referenced by Plot(), and Save_file_svg().

152 {
153  // Clear();
154  Clear();
155  //base
156  Draw_Line();
157  frame.Move();
158  //draw
159  Frame frame_loc=frame;
160 
161  double lenght_loc=lenght;
162  double sizePen_loc=sizePen;
163  int nb_branche=0;
164 
165  // Calcul du nombre de branche
166  for(int i=0;i<stock_prcent.Get_size();i++)
167  {
169  nb_branche++;
170  }
171 
172  //Calcul le nombre de branche
173  int nb_max=0;
174  for(int i=1;i<=niveau_max;i++)
175  {
176  nb_max=nb_max+(int)qPow(nb_branche,i);
177  }
178 
179  //Parametre la ProgressBar avec 0 --> nb de branche
180  ProgressBar->setMaximum(nb_max);
181  ProgressBar->setValue(0);
182  if(niveau_max==0)
183  {
184  ProgressBar->setMaximum(100);
185  ProgressBar->setValue(ProgressBar->maximum());
186  }
187  // Si couleur Auto
188  if(color_auto)
189  {
190  //
191  for(int i=0;i<=niveau_max;i++)
192  {
193  frame=frame_loc;
194  sizePen=sizePen_loc;
195  lenght=lenght_loc;
196  niveau=i;
197  Sub_Draw();
198  }
199  }
200  else
201  {
202  Sub_Draw();
203  }
204 }
bool color_auto
Definition: draw_tree.h:78
void Draw_Line()
Definition: draw_tree.cpp:260
void Clear()
Clear la class.
Definition: draw_tree.cpp:79
QProgressBar * ProgressBar
Definition: draw_tree.h:95
void Move()
Definition: frame.cpp:22
Frame frame
Definition: draw_tree.h:69
void Sub_Draw()
Definition: draw_tree.cpp:206
int niveau_max
Definition: draw_tree.h:72
double sizePen
Definition: draw_tree.h:74
Stock_Prcent stock_prcent
Definition: draw_tree.h:85
double lenght
Definition: draw_tree.h:73
lib gestion de repère 2D
Definition: frame.h:17
int niveau
Definition: draw_tree.h:71
double Get_Prcent_By_Index(int index)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Draw_Line()

void Draw_Tree::Draw_Line ( )
private

Definition at line 260 of file draw_tree.cpp.

References Frame::Add_alpha(), color, color_auto, file, frame, Frame::Get_x1(), Frame::Get_x2(), Frame::Get_y1(), Frame::Get_y2(), IsSaveSVG, Frame::Move(), scene, Frame::Set_d(), sizePen, with_bout, X_max, X_min, Y_max, and Y_min.

Referenced by Draw_Graph(), and Sub_Draw().

261 {
262  //qDebug() << "1 sizePen="<< sizePen;
263  double x1,x2,y1,y2;
264  x1=frame.Get_x1();
265  x2=frame.Get_x2();
266  y1=frame.Get_y1();
267  y2=frame.Get_y2();
268  //X_max
269  if(x1>X_max)
270  {
271  X_max=x1;
272  }
273  if(x2>X_max)
274  {
275  X_max=x2;
276  }
277  //X_min
278  if(x1<X_min)
279  {
280  X_min=x1;
281  }
282  if(x2<X_min)
283  {
284  X_min=x2;
285  }
286  //Y_max
287  if(y1>Y_max)
288  {
289  Y_max=y1;
290  }
291  if(y2>Y_max)
292  {
293  Y_max=y2;
294  }
295  //Y_min
296  if(y1<Y_min)
297  {
298  Y_min=y1;
299  }
300  if(y2<Y_min)
301  {
302  Y_min=y2;
303  }
304 
305 
306  Frame frame_temp;
307  QVector<QPointF> VectorQPointF;
308 
309  //P1
310  frame_temp=frame;
311  frame_temp.Add_alpha(90);
312  frame_temp.Set_d(sizePen/2);
313  VectorQPointF.append(QPointF(frame_temp.Get_x2(),frame_temp.Get_y2()));
314 
315  //P2
316  frame_temp=frame;
317  frame_temp.Move();
318  frame_temp.Add_alpha(90);
319  frame_temp.Set_d(sizePen/2);
320  VectorQPointF.append(QPointF(frame_temp.Get_x2(),frame_temp.Get_y2()));
321 
322  //P3
323  frame_temp=frame;
324  frame_temp.Move();
325  frame_temp.Add_alpha(-90);
326  frame_temp.Set_d(sizePen/2);
327  VectorQPointF.append(QPointF(frame_temp.Get_x2(),frame_temp.Get_y2()));
328 
329  //P4
330  frame_temp=frame;
331  frame_temp.Add_alpha(-90);
332  frame_temp.Set_d(sizePen/2);
333  VectorQPointF.append(QPointF(frame_temp.Get_x2(),frame_temp.Get_y2()));
334  //QVector<QPointF>
335  //QPolygonF()
336  QPolygonF PolygonF=QPolygonF(VectorQPointF);
337  //qDebug() << "2 sizePen="<< sizePen;
338  QColor Color ;
339  Color=color;
340  if(color_auto)
341  {
342  Color.setRed(qrand()%255);
343  Color.setGreen(qrand()%255);
344  Color.setBlue(qrand()%255);
345  }
346 
347  QPen Pen(Color);
348  //Pen.setWidth((int)sizePen);
349  Pen.setWidth(0);
350 
351  QBrush Brush(Color);
352 
353  scene->addPolygon(PolygonF,Pen,Brush);
354 
355  if(with_bout)
356  {
357  double X1,X2,Y1,Y2;
358  X1=x2-(sizePen/2);
359  Y1=y2-(sizePen/2);
360  X2=x2+(sizePen/2);
361  Y2=y2+(sizePen/2);
362  double dX,dY;
363  dX=X2-X1;
364  dY=Y2-Y1;
365  scene->addEllipse(X1,Y1,dX,dY,Pen,Brush);
366  }
367  //qDebug() << "3 sizePen="<< sizePen;
368  //SVG
369  //double x1,x2,y1,y2;
370  x1=frame.Get_x1()-X_min+100;
371  x2=frame.Get_x2()-X_min+100;
372  y1=frame.Get_y1()-Y_min+100;
373  y2=frame.Get_y2()-Y_min+100;
374 
375  if(IsSaveSVG)
376  {
377  if(file.open(QIODevice::Append | QIODevice::Text))
378  {
379  QTextStream out(&file);
380  out << "<line x1=\"" << x1 << "\" y1=\"" << y1 << "\" x2=\"" << x2 << "\" y2=\"" << y2 << "\" stroke=\"rgb(" << Color.red() <<"," << Color.green() << "," << Color.blue() << ")\" stroke-width=\"" << (int)sizePen << "\"/>\n";
381  if(with_bout)
382  {
383  out << "<circle cx=\"" << x2 <<"\" cy=\"" << y2 << "\" r=\"" << sizePen/2 << "\" fill=\"rgb(" << Color.red() <<"," << Color.green() << "," << Color.blue() << ")\"/> \n";
384  }
385  file.close();
386  }
387  //qDebug() << "4 sizePen="<< sizePen;
388  }
389 
390 }
bool color_auto
Definition: draw_tree.h:78
double Get_y1()
Definition: frame.cpp:46
double Y_min
Definition: draw_tree.h:93
double X_min
Definition: draw_tree.h:92
QFile file
Definition: draw_tree.h:87
double Get_x1()
Definition: frame.cpp:41
void Set_d(double d)
Definition: frame.cpp:17
bool IsSaveSVG
Definition: draw_tree.h:81
bool with_bout
Definition: draw_tree.h:79
void Move()
Definition: frame.cpp:22
Frame frame
Definition: draw_tree.h:69
QColor color
Definition: draw_tree.h:77
double Y_max
Definition: draw_tree.h:91
double sizePen
Definition: draw_tree.h:74
QGraphicsScene * scene
Definition: draw_tree.h:83
double Get_y2()
Definition: frame.cpp:56
double Get_x2()
Definition: frame.cpp:51
double X_max
Definition: draw_tree.h:90
lib gestion de repère 2D
Definition: frame.h:17
void Add_alpha(double alpha)
Definition: frame.cpp:12
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Init()

void Draw_Tree::Init ( QGraphicsScene *  scene,
QProgressBar *  ProgressBar_Plot 
)

Initialise la class.

Methode qui initalise la class

Parameters
*scene: Scene du QWidget_Graphique
*ProgressBar_Plot: Barre de progression des calculs

Definition at line 66 of file draw_tree.cpp.

References ProgressBar, and scene.

Referenced by Main_fenetre::Main_fenetre().

67 {
69  ProgressBar=ProgressBar_Plot;
70 }
QProgressBar * ProgressBar
Definition: draw_tree.h:95
QGraphicsScene * scene
Definition: draw_tree.h:83
Here is the caller graph for this function:

◆ Plot()

void Draw_Tree::Plot ( QWidget_trees Widget_trees,
QWidget_Config Widget_Config,
QWidget_Ratio Widget_Ratio,
QWidget_Graphique Widget_Graphique 
)

Desiner l'arbre.

Desine l'arbre

Parameters
QWidget_trees*Widget_trees : Valeur des largeurs des branches de l'arbre
QWidget_Config*Widget_Config : Configuration des branches
QWidget_Ratio*Widget_Ratio : Ratio des branches
QWidget_Graphique*Widget_Graphique : Configuration Graphique des branches

Definition at line 107 of file draw_tree.cpp.

References color, color_auto, Draw_Graph(), etat_ratio, QWidget_Graphique::Get_Color(), QWidget_Graphique::Get_Color_Auto(), QWidget_Config::Get_Lenght(), QWidget_Config::Get_Niveau(), QWidget_Ratio::Get_Ratio(), QWidget_Config::Get_SizePen(), QWidget_trees::Get_Stock_Prcent(), QWidget_Graphique::Get_with_Bout(), QWidget_Ratio::isChecked(), lenght, niveau, niveau_max, prcent_lenght, sizePen, stock_prcent, and with_bout.

Referenced by Main_fenetre::Plot_tree().

108 {
109  //Init
110  stock_prcent=Widget_trees->Get_Stock_Prcent();
111 
112  niveau=Widget_Config->Get_Niveau();
113  niveau_max=Widget_Config->Get_Niveau();
114 
115  lenght=Widget_Config->Get_Lenght();
116  sizePen=Widget_Config->Get_SizePen();
117 
118  prcent_lenght=Widget_Ratio->Get_Ratio()/100;
119  etat_ratio=Widget_Ratio->isChecked();
120 
121  color=Widget_Graphique->Get_Color();
122  color_auto=Widget_Graphique->Get_Color_Auto();
123 
124  with_bout=Widget_Graphique->Get_with_Bout();
125 
126  Draw_Graph();
127 
128  //Init
129  stock_prcent=Widget_trees->Get_Stock_Prcent();
130 
131  niveau=Widget_Config->Get_Niveau();
132  niveau_max=Widget_Config->Get_Niveau();
133 
134  lenght=Widget_Config->Get_Lenght();
135  sizePen=Widget_Config->Get_SizePen();
136 
137  prcent_lenght=Widget_Ratio->Get_Ratio()/100;
138  etat_ratio=Widget_Ratio->isChecked();
139 
140  color=Widget_Graphique->Get_Color();
141  color_auto=Widget_Graphique->Get_Color_Auto();
142 
143  with_bout=Widget_Graphique->Get_with_Bout();
144 }
bool color_auto
Definition: draw_tree.h:78
void Draw_Graph()
Desiner l&#39;abre.
Definition: draw_tree.cpp:151
double Get_SizePen()
bool with_bout
Definition: draw_tree.h:79
QColor color
Definition: draw_tree.h:77
int niveau_max
Definition: draw_tree.h:72
double sizePen
Definition: draw_tree.h:74
Stock_Prcent stock_prcent
Definition: draw_tree.h:85
Stock_Prcent Get_Stock_Prcent()
double lenght
Definition: draw_tree.h:73
int niveau
Definition: draw_tree.h:71
bool etat_ratio
Definition: draw_tree.h:76
double prcent_lenght
Definition: draw_tree.h:75
double Get_Ratio()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Save_file_svg()

void Draw_Tree::Save_file_svg ( QString  namefile)

Cree un fichier SVG.

Cree un fichier SVG

Parameters
QStringnamefile : Nom du fichier svg a ecrire

Definition at line 28 of file draw_tree.cpp.

References Draw_Graph(), file, IsSaveSVG, X_max, X_min, Y_max, and Y_min.

Referenced by Main_fenetre::save_svg().

29 {
30  //Marquage a true le flag SVG --> Creation d'un fichier svg
31  IsSaveSVG=true;
32  file.setFileName(namefile);
33  // Ouverture du fichier .svg
34  if (file.open(QIODevice::WriteOnly | QIODevice::Text))
35  {
36  // Ecriture du fichier .svg
37  QTextStream out(&file);
38  out << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
39  out << "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"" << X_max-X_min+200 <<"\" height=\"" << Y_max-Y_min+200 << "\">\n";
40  // Fermeture en ecriture du fichier .svg
41  file.close();
42  //Calcul des branches
43  Draw_Graph();
44  //Ecriture de la fin du fichier
45  if(file.open(QIODevice::Append | QIODevice::Text))
46  {
47  QTextStream out(&file);
48  out << "</svg>";
49  file.close();
50  }
51 
52 
53  }
54  //Marquage a false le flag SVG --> Pas de creation de fichier svg
55  IsSaveSVG=false;
56 }
double Y_min
Definition: draw_tree.h:93
void Draw_Graph()
Desiner l&#39;abre.
Definition: draw_tree.cpp:151
double X_min
Definition: draw_tree.h:92
QFile file
Definition: draw_tree.h:87
bool IsSaveSVG
Definition: draw_tree.h:81
double Y_max
Definition: draw_tree.h:91
double X_max
Definition: draw_tree.h:90
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Sub_Draw()

void Draw_Tree::Sub_Draw ( )
private

Definition at line 206 of file draw_tree.cpp.

References Frame::Add_alpha(), color_auto, Draw_Line(), etat_ratio, frame, Stock_Prcent::Get_Angle_By_Index(), Stock_Prcent::Get_size(), lenght, Frame::Move(), niveau, PI, prcent_lenght, ProgressBar, Frame::Set_d(), sizePen, and stock_prcent.

Referenced by Draw_Graph().

207 {
208 
209  Frame frame_loc = frame;
210  double lenght_loc=lenght;
211  double sizePen_loc=sizePen;
212 
213  frame_loc.Add_alpha(90);
214  Frame frame_temp = frame_loc;
215  niveau--;
216  if(niveau>-1)
217  {
218  double angle=0;
219  double angle_temp=0;
220  for(int i=0;i<stock_prcent.Get_size();i++)
221  {
222  angle_temp=stock_prcent.Get_Angle_By_Index(i);
223  if(angle_temp>0)
224  {
225  frame_temp=frame_loc;
226 
227  double l=qCos(angle_temp/2*PI/180)*sizePen_loc/2;
228  double d=qSin(angle_temp/2*PI/180)*sizePen_loc/2;
229 
230  frame_temp.Add_alpha(-angle-angle_temp/2);
231  frame_temp.Set_d(l);
232  frame_temp.Move();
233 
234  sizePen=d*2;
235  if(etat_ratio)
236  lenght=lenght_loc*prcent_lenght;
237  else
238  lenght=sizePen;
239  frame=frame_temp;
240  frame.Set_d(lenght);
241 
242  if(niveau==0 || !color_auto)
243  {
244  Draw_Line();
245  ProgressBar->setValue(ProgressBar->value()+1);
246  }
247 
248 
249  frame.Move();
250  Sub_Draw();
251 
252  angle=angle+angle_temp;
253 
254  }
255  }
256 
257  }
258  niveau++;
259 }
bool color_auto
Definition: draw_tree.h:78
void Draw_Line()
Definition: draw_tree.cpp:260
QProgressBar * ProgressBar
Definition: draw_tree.h:95
void Set_d(double d)
Definition: frame.cpp:17
double Get_Angle_By_Index(int index)
void Move()
Definition: frame.cpp:22
#define PI
Definition: frame.h:5
Frame frame
Definition: draw_tree.h:69
void Sub_Draw()
Definition: draw_tree.cpp:206
double sizePen
Definition: draw_tree.h:74
Stock_Prcent stock_prcent
Definition: draw_tree.h:85
double lenght
Definition: draw_tree.h:73
lib gestion de repère 2D
Definition: frame.h:17
int niveau
Definition: draw_tree.h:71
bool etat_ratio
Definition: draw_tree.h:76
double prcent_lenght
Definition: draw_tree.h:75
void Add_alpha(double alpha)
Definition: frame.cpp:12
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ color

QColor Draw_Tree::color
private

Definition at line 77 of file draw_tree.h.

Referenced by Draw_Line(), and Plot().

◆ color_auto

bool Draw_Tree::color_auto
private

Definition at line 78 of file draw_tree.h.

Referenced by Draw_Graph(), Draw_Line(), Plot(), and Sub_Draw().

◆ etat_ratio

bool Draw_Tree::etat_ratio
private

Definition at line 76 of file draw_tree.h.

Referenced by Plot(), and Sub_Draw().

◆ file

QFile Draw_Tree::file
private

Definition at line 87 of file draw_tree.h.

Referenced by Draw_Line(), and Save_file_svg().

◆ frame

Frame Draw_Tree::frame
private

Definition at line 69 of file draw_tree.h.

Referenced by Clear(), Draw_Graph(), Draw_Line(), and Sub_Draw().

◆ IsSaveSVG

bool Draw_Tree::IsSaveSVG
private

Definition at line 81 of file draw_tree.h.

Referenced by Clear(), Draw_Line(), Draw_Tree(), and Save_file_svg().

◆ lenght

double Draw_Tree::lenght
private

Definition at line 73 of file draw_tree.h.

Referenced by Clear(), Draw_Graph(), Plot(), and Sub_Draw().

◆ niveau

int Draw_Tree::niveau
private

Definition at line 71 of file draw_tree.h.

Referenced by Draw_Graph(), Plot(), and Sub_Draw().

◆ niveau_max

int Draw_Tree::niveau_max
private

Definition at line 72 of file draw_tree.h.

Referenced by Draw_Graph(), and Plot().

◆ prcent_lenght

double Draw_Tree::prcent_lenght
private

Definition at line 75 of file draw_tree.h.

Referenced by Plot(), and Sub_Draw().

◆ ProgressBar

QProgressBar* Draw_Tree::ProgressBar
private

Definition at line 95 of file draw_tree.h.

Referenced by Draw_Graph(), Init(), and Sub_Draw().

◆ scene

QGraphicsScene* Draw_Tree::scene
private

Definition at line 83 of file draw_tree.h.

Referenced by Clear(), Draw_Line(), and Init().

◆ sizePen

double Draw_Tree::sizePen
private

Definition at line 74 of file draw_tree.h.

Referenced by Draw_Graph(), Draw_Line(), Plot(), and Sub_Draw().

◆ stock_prcent

Stock_Prcent Draw_Tree::stock_prcent
private

Definition at line 85 of file draw_tree.h.

Referenced by Draw_Graph(), Plot(), and Sub_Draw().

◆ with_bout

bool Draw_Tree::with_bout
private

Definition at line 79 of file draw_tree.h.

Referenced by Draw_Line(), and Plot().

◆ X_max

double Draw_Tree::X_max
private

Definition at line 90 of file draw_tree.h.

Referenced by Clear(), Draw_Line(), and Save_file_svg().

◆ X_min

double Draw_Tree::X_min
private

Definition at line 92 of file draw_tree.h.

Referenced by Clear(), Draw_Line(), and Save_file_svg().

◆ Y_max

double Draw_Tree::Y_max
private

Definition at line 91 of file draw_tree.h.

Referenced by Clear(), Draw_Line(), and Save_file_svg().

◆ Y_min

double Draw_Tree::Y_min
private

Definition at line 93 of file draw_tree.h.

Referenced by Clear(), Draw_Line(), and Save_file_svg().


The documentation for this class was generated from the following files: